package com.wwe.kotlinstudy.util

/**
 * @name KotlinStudy
 * @package name：com.wwe.kotlinstudy.util
 * @anthor DavidZhang
 * @time 2018/4/26 17:56
 * @class describe
 */

/*constructor be called
name'set be called value is AJ.Styles
age'set be called value is 35
name'get be called value is AJ.Styles
age'get be called value is 35
Person(name='AJ.Styles', age=35)*/

class SuperStart {

    constructor(name: String = "AJ.Styles", age: Int = 35) {
        println("constructor be called")
        this.name = name
        this.age = age
    }

    //属性,自定义他的get/set
    var name: String = ""
        get() {
            //如果只有一句的话可以写成“get() = 函数语句”的形式
            println("name'get be called value is $field")
            return field.toString()
        }
        set(value) {
            println("name'set be called value is $value")
            field = if (value.isEmpty()) "" else value[0].toUpperCase() + value.substring(1)
        }

    var age: Int = 0
        set(value) {
            println("age'set be called value is $value")
            field = value

        }
        get() {
            println("age'get be called value is $field")
            return field;
        }

    override fun toString(): String {
        //访问属性，一定会执行get/set
        return "Person(name='${name}', age=$age)"
    }



}